package img;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.qrcode.QRCodeWriter;

import javax.imageio.ImageIO;
import java.io.File;
import java.util.HashMap;

/**
 * @author wzby
 * @Date: 2022/8/4 9:55
 */
public class ImgQr1 {
    public static void main(String[] args) throws Exception {
        //String qr = "ch09/src/pho/qr1.png";
        //生成QRCcode
        var zt = new HashMap<EncodeHintType,Object>();
        zt.put(EncodeHintType.CHARACTER_SET,"utf-8");
        //修复中文乱码

        //var bm = new QRCodeWriter().encode("jkgkjhjk", BarcodeFormat.QR_CODE,400,400,zt);
        var bm = new QRCodeWriter().encode("http://m.qpic.cn/psc?/V131pW4P235CQH/ruAMsa53pVQWN7FLK88i5jmU63jnATjw0Cj8EJrcXm6.rH8Tumrwivy4LzVnAIxMMsnXzdVengITdkF4VwwpxnYtu.Uz5y.pUIZcj1w7bTE!/b&bo=oAU4BAAAAAABB7k!&rf=viewer_4", BarcodeFormat.QR_CODE,400,400,zt);


        var i = MatrixToImageWriter.toBufferedImage(bm);
        ImageIO.write(i,"png",new File("ch09/src/pho/qr1.png"));
        Runtime.getRuntime().exec("cmd /k start ch09/src/pho/qr1.png");
    }
}
